package com.lzh.vod.controller;

import com.aliyuncs.exceptions.ClientException;
import com.lzh.commonutils.CommonResult;
import com.lzh.vod.service.VodService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author lzhstart
 * @create 2021/5/10 17:20
 */
@CrossOrigin
@RestController
@RequestMapping("/eduVod")
public class VodController {

    @Autowired
    private VodService vodService;

    @ApiOperation(value = "上传视频")
    @PostMapping("/upload")
    public CommonResult uploadVideo(MultipartFile file) {
        String videoId = vodService.uploadVideo(file);
        return CommonResult.ok().message("视频上传成功").data("videoId",videoId);
    }

    @ApiOperation(value = "获取视频播放凭证")
    @GetMapping("/getPlayAuth")
    public CommonResult getPlayByAuth(@RequestParam String id) throws ClientException {
        String vodPlayAuth = vodService.getVodPlayAuth(id);
        return CommonResult.ok().data("playAuth",vodPlayAuth);
    }
    @ApiOperation(value = "获取视频播放凭证")
    @GetMapping("/getPlayUrl")
    public CommonResult getPlayByUrl(@RequestParam String id) throws ClientException {
        String vodPlayUrl = vodService.getVodPlayUrl(id);
        return CommonResult.ok().data("playUrl",vodPlayUrl);
    }

    /**
     * 删除单个视频
     * @param videoId
     * @return
     */
    @ApiOperation(value = "删除视频")
    @DeleteMapping("/removeAliyunVodById")
    public CommonResult removeVideo(@RequestParam String videoId) {
        vodService.removeVideo(videoId);
        return CommonResult.ok().message("视频成功删除");
    }

    /**
     * 批量删除视频
     * @param videoList
     * @return
     */
    @ApiOperation(value = "批量删除视频")
    @DeleteMapping("/removeAliyunVodBatch")
    public CommonResult removeBatchVideo(@RequestParam("videoList") List videoList) {
        vodService.removeBatchVideos(videoList);
        return CommonResult.ok().message("批量视频删除成功");
    }

}
